import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/viewmodel/food/single_order_select_view_model.dart';

class SingleOrderSelectPlacePage extends BaseStatefulMvvmWidget {
  final String orderType;
  final String id;
  final String? oldId;
  final int? mealId;


  SingleOrderSelectPlacePage(this.orderType, this.id, {this.oldId,this.mealId});

  @override
  State<StatefulWidget> createState() => _SingleOrderSelectPlaceState();
}

class _SingleOrderSelectPlaceState extends BaseMvvmState<
    SingleOrderSelectPlaceViewModel, SingleOrderSelectPlacePage> {
  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        (viewModel.orderType == '1'
                ? ListView(
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          CommonText('场所', textSize: 17).addToContainer(
                              margin: EdgeInsets.symmetric(
                                  horizontal: 16, vertical: 20)),
                          viewModel.selectPlaceWidget(),
                          Container(
                            height: 16,
                          )
                        ],
                      ).addToContainer(color: Colors.white),
                      Container(
                        height: 16,
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          CommonText('选择用餐时间', textSize: 17).addToContainer(
                              margin: EdgeInsets.symmetric(
                                  horizontal: 16, vertical: 20)),
                          viewModel.selectDateWidget(),
                          Container(
                            height: 13,
                          ),
                          viewModel.selectFoodTimeWidget(),
                          Container(
                            height: 16,
                          ),
                        ],
                      ).addToContainer(color: Colors.white),
                      Container(
                        height: 16,
                      ),
                      viewModel.selectOldWidget(),
                      Container(
                        height: 10,
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          CommonText('选择用餐方式', textSize: 17).addToContainer(
                              margin: EdgeInsets.symmetric(
                                  horizontal: 16, vertical: 20)),
                          viewModel.selectFoodTypeWidget(),
                          Container(
                            height: 16,
                          )
                        ],
                      ).addToContainer(color: Colors.white),
                      Container(
                        height: 16,
                      ),
                      IconTitleTextWidget(
                        '就餐人数',
                        hintText: '请选择就餐人数',
                        text: '${viewModel.useNumber}人',
                      ).onTap(() {
                        viewModel.selectUseNumber();
                      })
                    ],
                  )
                : ListView(
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          CommonText('场所', textSize: 17).addToContainer(
                              margin: EdgeInsets.symmetric(
                                  horizontal: 16, vertical: 20)),
                          viewModel.selectPlaceWidget(),
                          Container(
                            height: 16,
                          )
                        ],
                      ).addToContainer(color: Colors.white),
                      Container(
                        height: 10,
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          CommonText('点餐时间', textSize: 17).addToContainer(
                              margin: EdgeInsets.symmetric(
                                  horizontal: 16, vertical: 20)),
                          viewModel.selectWeekTime(),
                          Container(
                            height: 16,
                          )
                        ],
                      ).addToContainer(color: Colors.white),
                      Container(
                        height: 10,
                      ),
                      viewModel.selectOldWidget(),
                      Container(
                        height: 10,
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          CommonText('选择用餐方式', textSize: 17).addToContainer(
                              margin: EdgeInsets.symmetric(
                                  horizontal: 16, vertical: 20)),
                          viewModel.selectFoodTypeWidget(),
                          Container(
                            height: 16,
                          )
                        ],
                      ).addToContainer(color: Colors.white),
                    ],
                  ))
            .setWeight(1),
        ElevatedButton(
          onPressed: () {
            viewModel.nextStep();
          },
          child: CommonText('下一步', textColor: Colors.white),
          style: ButtonStyle(
              backgroundColor: WidgetStateProperty.all(Colours.app_main),
              minimumSize: WidgetStateProperty.all(Size(double.infinity, 50)),
              shape: WidgetStateProperty.all(RoundedRectangleBorder())),
        )
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Color(0xfff1f1f1),
      appBar: AppBar(
        title: Text('点餐'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  SingleOrderSelectPlaceViewModel createViewModel() {
    return SingleOrderSelectPlaceViewModel(context, widget.orderType, widget.id,
        oldId: widget.oldId,mealId: widget.mealId);
  }

  @override
  void onRetryClick() {
    viewModel.getSiteList();
  }
}
